<%@ page language="java" import="java.util.*,com.lab.po.Student"
	pageEncoding="utf-8"%>
<%@ page import="com.lab.dao.impl.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<title>显示用户信息</title>

     <style type="text/css">
       input[type="text"]{
              height: auto;
	          margin-top: 8px;
	          padding: 3px 9px;
            }
        a {
  			cursor:pointer;
		}
     </style>
     <script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery-1.8.3.js"></script>
	</head>

<script type="text/javascript">
function query(currentPage){
	//去除所有的空格
	var regExp=/\s/g;
	var stuid=$("#stuid").val().replace(regExp,"");
	var stuname=$("#stuname").val().replace(regExp,"");
	var maj_name=$("#maj_name").val().replace(regExp,"");
	var address=$("#address").val().replace(regExp,"");
    	$.ajax({
    		url:"${pageContext.request.contextPath}/showStudentAjax",
    		type:"post",
    		data:{stuid:stuid,stuname:stuname,maj_name:maj_name,address:address,currentPage:currentPage,flag:"true"},
    		dataType:"json",
    		success:function(result){
    			$("#stutable").html('');
    			
    			  $.each(result,function(inx,student){ 
   				 	 $("#stutable").append("<tr><td style='width:150px'>"+student.stId+"</td>"
   							+"<td style='width:70px'>"+student.stName+"</td>"
   							+"<td style='width:90px'>"+student.stSex+"</td>"
   							+"<td style='width:80px'>"+student.stAge+"</td>"
   							+"<td style='width:140px'>"+student.stTel+"</td>"
   							+"<td style='width:160px'>"+student.maj_name+"</td>"
   							+"<td style='width:120px'>"+student.stAddress+"</td>"
   							+"<td><a onclick='det("+student.stId+")' class=\"btn btn-danger\">删除</a>&nbsp;"
   							+"<a href=\"preServlet?method=updateStudent&id="+student.stId+"\" class=\"btn btn-primary\">更新</a>&nbsp;"
   							+"<a href=\"preServlet?method=updateScore&id="+student.stId+"\" class=\"btn btn-success\">成绩录入</a></td></tr>");
    			}); 
    		}

    	});

$.ajax({
	url:"${pageContext.request.contextPath}/pageAjax",
	type:"post",
	data:{stuid:stuid,stuname:stuname,maj_name:maj_name,address:address,currentPage:currentPage,flag:"true"},
	dataType:"text",
	success:function(result){	
		$("#pageid").html('');
			$("#pageid").append(result);
	}
});
}

function det(id){
	if(confirm("确定要删除吗？")) {
		location.href = "deleteServlet?method=deleteStudent&id=" + id;
	}
}
</script>
	<body>

        <div class="container" >
        	<div align="center">
          	 学号：<input type="text" name="searchId" id="stuid" placeholder="学生学号...">&nbsp;
          	 姓名：<input type="text" name="stuname" id="stuname" placeholder="学生姓名..."/>&nbsp;
          	 专业：<input type="text" name="maj_name" id="maj_name" placeholder="专业..."/>&nbsp;
          	 籍贯：<input type="text" name="address" id="address" placeholder="籍贯..."/>
          	 <i class="icon-search"></i>&nbsp;
          	 <button type="button" class="btn btn-inverse" onclick="query(1)"> 查找</button>
          	 </div>
        </div>
		<table  class="table table-hover table-condensed">
		    <tr>
				<td align="center"><strong>学号</strong></td>
				<td align="center" style="width:80px"><strong>姓名</strong></td>
				<td align="center" style="width:80px"><strong>性别</strong></td>
				<td align="center" style="width:80px"><strong>年龄</strong></td>
				<td align="center"><strong>电话</strong></td>
				<td align="center"><strong>专业</strong></td>
				<td align="center"><strong>籍贯</strong></td>
				<td align="center" ><strong>执行操作</strong></td>
			</tr>
			
			<table class="table table-hover table-condensed" id="stutable">
			<c:forEach items="${list}" var="student">
				<tr>
					<td style="width:150px"><c:out value="${student.stId}" /></td>
					<td style="width:70px"><c:out value="${student.stName}" /></td>
					<td style="width:90px"><c:out value="${student.stSex}" /></td>
					<td style="width:80px"><c:out value="${student.stAge}" /></td>
					<td style="width:140px"><c:out value="${student.stTel}" /></td>
					<td style="width:160px"><c:out value="${student.maj_name}" /></td>
					<td style="width:120px"><c:out value="${student.stAddress}" /></td>
					<td>
						<a  onclick="det(${student.stId})" class="btn btn-danger">删除</a>
						<a href="preServlet?method=updateStudent&id=${student.stId}" class="btn btn-primary">更新</a>
						<a href="preServlet?method=updateScore&id=${student.stId}" class="btn btn-success">成绩录入</a>
					</td>
				</tr>
			</c:forEach>
			</table>
			<table class="table table-hover table-condensed" id="pageid">
			<tr>
			<td colspan="8">
			当前页：${PageBean.currentPage }/${PageBean.totalPage }&nbsp;
					<a href="${pageContext.request.contextPath}/showAllServlet?method=showStudent&currentPage=1">首页</a>&nbsp;
					<c:if test="${PageBean.currentPage==1 }">
						<a href="${pageContext.request.contextPath}/showAllServlet?method=showStudent&currentPage=1">上一页</a>&nbsp;
					</c:if>
					<c:if test="${PageBean.currentPage!=1 }">
						<a href="${pageContext.request.contextPath}/showAllServlet?method=showStudent&currentPage=${PageBean.currentPage-1}">上一页</a>&nbsp;
					</c:if>
					<c:if test="${PageBean.currentPage==PageBean.totalPage }">
						<a href="${pageContext.request.contextPath}/showAllServlet?method=showStudent&currentPage=${PageBean.totalPage}">下一页</a>&nbsp;
					</c:if>
					<c:if test="${PageBean.currentPage!=PageBean.totalPage  }">
						<a href="${pageContext.request.contextPath}/showAllServlet?method=showStudent&currentPage=${PageBean.currentPage+1}">下一页</a>&nbsp;
					</c:if>
					<a href="${pageContext.request.contextPath}/showAllServlet?method=showStudent&currentPage=${PageBean.totalPage}">末页</a>
			</td>
			</tr>
			</table>
		</table>	
		<hr>
		<a href="main.jsp" class="btn btn-success">返回主菜单</a>
		<hr>


	</body>
</html>
